package com.dayuanit.booksystem.v3.net;

import com.dayuanit.booksystem.v3.entity.Publisher;
import com.dayuanit.booksystem.v3.net.common.DypRequest;
import com.dayuanit.booksystem.v3.net.common.DypResponse;
import com.dayuanit.booksystem.v3.net.common.DypServlet;
import com.dayuanit.booksystem.v3.service.PublisherService;
import com.dayuanit.booksystem.v3.service.impl.PublisherServiceImpl;

/**
 * 处理出版社的请求
 */
public class PublisherDypServlet implements DypServlet {

    private PublisherService publisherService = new PublisherServiceImpl();

    /**
     * 处理出版社的各种请求
     */
    public void doPost(DypRequest dypRequest, DypResponse dypResponse) {
        if (dypRequest.getFuntionNumber() == 2000) {
            //得到客户端传过来的参数集合
            publisherService.addPublisher(dypRequest.getParamValue("name"), dypRequest.getParamValue("address"));
            dypResponse.setData("添加成功");
        }

        if (dypRequest.getFuntionNumber() == 2001) {
            Publisher publisher = publisherService.queryPublisher(Long.parseLong(dypRequest.getParamValue("publisherId")));
            dypResponse.setData(publisher.toString());
        }

    }

    @Override
    public void doGet(DypRequest request, DypResponse dypResponse) {

    }

    @Override
    public void doPut(DypRequest request, DypResponse dypResponse) {

    }
}
